/* Theme Variables */
:root[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --accent-primary: #3b82f6;
    --accent-secondary: #60a5fa;
    --border-color: #e2e8f0;
    --card-bg: #ffffff;
    --sidebar-bg: #ffffff;
    --hover-bg: #f1f5f9;
    --stat-box-bg: #f8fafc;
    --activity-bg: #f8fafc;
    --text-muted: #64748b;
    --stats-box-highlight: #f0f9ff;
    --token-usage-bg: #eff6ff;
    --stats-border: #e2e8f0;
    --image-invert: 0;
}

:root[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #e2e8f0;
    --accent-primary: #60a5fa;
    --accent-secondary: #93c5fd;
    --border-color: #334155;
    --card-bg: #1e293b;
    --sidebar-bg: #1e293b;
    --hover-bg: #334155;
    --stat-box-bg: #1e293b;
    --activity-bg: #1e293b;
    --text-muted: #cbd5e1;
    --stats-box-highlight: #172554;
    --token-usage-bg: #1e3a8a;
    --stats-border: #1e40af;
    --image-invert: 1;
}

/* Add image inversion for dark mode */
[data-theme="dark"] img:not(.no-invert) {
    filter: invert(var(--image-invert));
    transition: filter 0.3s ease;
}

[data-theme="dark"] select,
[data-theme="dark"] input,
[data-theme="dark"] textarea {
    background-color: #1e293b !important;  /* Dunkler Hintergrund */
    color: #f1f5f9 !important;            /* Heller Text */
    border-color: #475569 !important;      /* Sichtbare Umrandung */
}

/* Fix für den JSON-Viewer in debug.ejs */
[data-theme="dark"] .jsonview {
    background-color: #1e293b;
    color: #f1f5f9;
}

/* Fix für den Content-Preview in manual.ejs */
[data-theme="dark"] #contentPreview {
    background-color: #1e293b;
    color: #f1f5f9;
}

[data-theme="dark"] #apiKeyContainer {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

[data-theme="dark"] #copyNotification {
    background-color: var(--stats-box-highlight);
    color: var(--text-primary);
    border-color: var(--stats-border);
}


/* Base chart container sizing */
.material-card .chart-container {
    position: relative;
    width: 100%;
    margin: 0 auto;
}

/* Token Distribution chart sizing */
.material-card:has(#tokenDistribution) .chart-container {
    height: 200px;
    color: white;
}

/* Document Types chart sizing */
.material-card:has(#documentTypes) .chart-container {
    height: 200px;  /* Reduced height for donut chart */
    max-width: 200px; /* Constrain width to maintain circular shape */
    margin: 0 auto; /* Center the chart */
}

/* Task Runner Dark Mode Styles */
/* Processing/Idle Container Background Override */
[data-theme="dark"] .bg-white.rounded-xl.border.border-gray-100 {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
}
[data-theme="dark"] .material-card {
    background-color: var(--card-bg);
    border-color: var(--border-color);
}

/* Dark mode compatibility */
[data-theme="dark"] .material-card .chart-container {
    background-color: var(--card-bg);
}

[data-theme="dark"] .material-card:has(#documentTypes) .chart-container {
    background-color: var(--card-bg);
}

/* Active Processing Card */
[data-theme="dark"] #processingContainer .border-blue-100 {
    border-color: #1e3a8a; /* Darker blue for spinner border */
}

[data-theme="dark"] #processingContainer .border-t-blue-500 {
    border-top-color: var(--accent-primary);
}

[data-theme="dark"] #processingContainer .text-blue-500 {
    color: var(--accent-primary);
}

[data-theme="dark"] #processingContainer .bg-blue-50 {
    background-color: #1e3a8a !important;
}

[data-theme="dark"] #processingContainer .bg-gray-50,
[data-theme="dark"] .bg-gray-50 {
    background-color: var(--bg-secondary) !important;
}

[data-theme="dark"] #processingContainer .text-blue-700 {
    color: #93c5fd;
}

[data-theme="dark"] #processingContainer .text-gray-600 {
    color: var(--text-secondary);
}

/* Idle Container */
[data-theme="dark"] #idleContainer .bg-gray-50 {
    background-color: var(--bg-secondary);
}

[data-theme="dark"] #idleContainer .text-gray-400 {
    color: var(--text-muted);
}

[data-theme="dark"] #idleContainer .text-gray-600 {
    color: var(--text-secondary);
}

/* Stats Grid */
[data-theme="dark"] .grid-cols-2 .bg-white {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
}

[data-theme="dark"] .text-gray-500 {
    color: var(--text-muted);
}

[data-theme="dark"] .text-gray-600 {
    color: var(--text-secondary);
}

[data-theme="dark"] .font-bold {
    color: var(--text-primary);
}

/* Status Last Updated */
[data-theme="dark"] #statusLastUpdated.text-gray-500 {
    color: var(--text-muted);
}

/* Chart Containers */
[data-theme="dark"] .chart-container {
    background-color: var(--card-bg);
    border-color: var(--border-color);
}

/* Add hover states for cards in dark mode */
[data-theme="dark"] .material-card:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3),
                0 4px 6px -2px rgba(0, 0, 0, 0.15);
}

/* Ensure text remains visible in dark mode */
[data-theme="dark"] .card-title {
    color: var(--text-primary);
}

[data-theme="dark"] .font-medium {
    color: var(--text-primary);
}

/* Dark mode styles for tag spans */
[data-theme="dark"] .inline-flex[data-tag-id] {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .inline-flex[data-tag-id] button {
    color: var(--text-secondary);
}

[data-theme="dark"] .inline-flex[data-tag-id] button:hover {
    color: var(--text-primary);
}

/* Style for tags with blue background */
[data-theme="dark"] .bg-blue-100.inline-flex[data-tag-id] {
    background-color: var(--token-usage-bg);
    color: var(--text-primary);
    border: 1px solid var(--stats-border);
}

[data-theme="dark"] .bg-blue-100.inline-flex[data-tag-id] button {
    color: var(--accent-primary);
}

[data-theme="dark"] .bg-blue-100.inline-flex[data-tag-id] button:hover {
    color: var(--accent-secondary);
}

/* Base Styles */
body {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    padding: 0;
    min-height: 100vh;
    position: relative;
    font-family: Arial, sans-serif; 
    margin: 20px; 
    line-height: 1.6;
}

/* Layout */
.layout-container {
    display: flex;
    min-height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
}

.sidebar-header {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: var(--accent-primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.brand-title {
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--text-primary);
}

.sidebar-nav {
    padding: 1.5rem 0;
}

.sidebar-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s ease;
}

.sidebar-link:hover {
    background: var(--hover-bg);
    color: var(--accent-primary);
}

.sidebar-link.active {
    background: var(--hover-bg);
    color: var(--accent-primary);
    border-right: 3px solid var(--accent-primary);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 2rem;
    width: calc(100% - 260px);
    overflow-y: auto;
    height: 100vh;
}

.content-wrapper {
    width: 100%;
    padding-right: 2rem;
}

.content-header {
    margin-bottom: 2rem;
}

.content-title {
    font-size: 1.875rem;
    font-weight: bold;
    color: var(--text-primary);
}

/* Cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
    width: 100%;
}

.col-span-2 {
    grid-column: span 2;
}

.material-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
                0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.material-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
                0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.card-title {
    font-size: 1.25rem;
    font-weight: bold;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* Stats Box */
.stat-box {
    background: var(--stat-box-bg);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--stats-border);
    transition: all 0.2s ease;
    color: var(--text-primary);
}

.stat-box:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    background: var(--hover-bg);
}

/* Improved Token Usage Styling */
.bg-blue-50 {
    background-color: var(--token-usage-bg) !important;
    color: var(--text-primary);
    border: 1px solid var(--stats-border);
}

.bg-gray-50 {
    background-color: var(--stat-box-bg) !important;
    color: var(--text-primary);
    border: 1px solid var(--stats-border);
}

/* Text colors for stats */
.text-gray-600 {
    color: var(--text-muted) !important;
}

.font-semibold {
    color: var(--text-primary);
}

.text-xl {
    color: var(--text-primary);
}

/* Stats legend improvements */
.stats-legend .stat-item {
    padding: 0.75rem;
    border-radius: 6px;
    background: var(--stat-box-bg);
    margin-bottom: 0.5rem;
}

.stat-item span {
    color: var(--text-primary);
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-container {
    position: relative;
    background: var(--card-bg);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1),
                0 10px 10px -5px rgba(0, 0, 0, 0.04);
    transform: translateY(20px);
    transition: transform 0.3s ease;
    overflow: hidden;
    border: 1px solid var(--border-color);
    z-index: 51;
}

.modal.show .modal-container {
    transform: translateY(0);
}

.modal-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card-bg);
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.modal-content {
    padding: 1.25rem;
    overflow-y: auto;
    max-height: calc(80vh - 70px);
    background: var(--card-bg);
}

/* Theme Toggle */
.theme-toggle {
    position: fixed;
    top: 1.25rem;
    right: 1.25rem;
    z-index: 1000;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    background: var(--hover-bg);
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .card-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .layout-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        position: relative;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
        width: 100%;
    }

    .card-grid {
        grid-template-columns: 1fr;
    }

    .col-span-2 {
        grid-column: span 1;
    }

    .modal-container {
        width: 95%;
        margin: 1rem;
    }
}

/* Modal Content Styles */
.detail-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.detail-item {
    background: var(--stat-box-bg);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--stats-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.detail-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    background: var(--hover-bg);
}

.detail-item-name {
    color: var(--text-primary);
    font-weight: 500;
}

.detail-item-info {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.content-header {
    background-color: var(--bg-primary);
}

.content-title {
    color: var(--text-primary);
}

#apiKeyContainer {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.checkbox-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }

  .checkbox-container input[type="checkbox"] {
    margin-right: 5px;
  }

  @media (max-width: 600px) {
    .checkbox-container {
      flex-direction: column;
    }
  }

/* Mobile Menu Button */
.mobile-menu-button {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 9999;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border: none;
    border-radius: 4px;
    color: var(--text-primary);
    cursor: pointer;
    width: 48px;
    height: 48px;
    align-items: center;
    justify-content: center;
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
}

.sidebar-overlay.active {
    display: block;
}

/* Theme Toggle */
.theme-toggle {
    z-index: 9999;
}

/* Base Sidebar Styles */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease-in-out;
}

/* Mobile Styles */
@media (max-width: 768px) {
    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 4rem 1rem 1rem 1rem;
        height: 100vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar {
        position: fixed;
        height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .layout-container {
        display: block;
        height: 100vh;
        overflow: hidden;
    }

    body {
        overflow-y: hidden;
    }

    /* Enable scrolling when sidebar is closed */
    body:not(.sidebar-active) {
        overflow-y: auto;
    }

    .mobile-menu-button {
        display: flex;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 85%;
        max-width: 320px;
        transform: translateX(-100%);
        z-index: 999;
        background: var(--bg-secondary);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    /* Ensure sidebar content is clickable */
    .sidebar-nav,
    .sidebar-link,
    .sidebar-header,
    .brand-icon,
    .brand-title {
        position: relative;
        z-index: 999;
        pointer-events: auto !important;
    }

    .sidebar-link {
        display: flex;
        align-items: center;
        padding: 1rem 1.5rem;
        color: var(--text-secondary);
        text-decoration: none;
        transition: all 0.2s ease;
        cursor: pointer;
    }

    .sidebar-link:hover {
        background: var(--hover-bg);
        color: var(--accent-primary);
    }

    .sidebar-link.active {
        background: var(--hover-bg);
        color: var(--accent-primary);
        border-right: 3px solid var(--accent-primary);
    }

    /* Reset main content */
    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 4rem 1rem 1rem 1rem;
    }

    /* Layout container */
    .layout-container {
        display: flex;
        min-height: 100vh;
        width: 100%;
    }
}

/* Custom Scrollbar */
.main-content::-webkit-scrollbar,
.sidebar::-webkit-scrollbar {
    width: 8px;
}

.main-content::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.main-content::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
    background: var(--accent-secondary);
    border-radius: 4px;
}
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--accent-secondary);
    border-radius: 4px;
}